<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片压缩工具</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            padding: 20px;
            background-color: #f8f9fa;
            color: #212529;
            line-height: 1.5;
        }
        .container {
            background-color: #ffffff;
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            max-width: 700px;
            margin: 40px auto;
            border: 1px solid #dee2e6;
        }
        h1 {
            text-align: center;
            color: #343a40;
            margin-bottom: 30px;
            font-weight: 500;
        }
        .form-group {
            margin-bottom: 30px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #495057;
        }
        input[type="file"], select {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ced4da;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 1rem;
            background-color: #fff;
            transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
        }
        input[type="file"]:focus, select:focus {
             border-color: #86b7fe;
             outline: 0;
             box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
        }
        input[type="file"] {
            cursor: pointer;
        }
        /* Style for selected file info display */
        .selected-files-info {
            margin-top: 10px;
            font-size: 0.9em;
            color: #6c757d;
            word-break: break-word; /* Allow long lists to wrap */
            max-height: 6em; /* Limit height and add scroll if needed */
            overflow-y: auto; /* Add scroll for long lists */
            padding: 5px; /* Optional padding */
            border: 1px dashed #ced4da; /* Optional border */
            border-radius: 4px;
            background-color: #f8f9fa;
        }
        /* Style for static output format display */
        .output-format-display {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ced4da;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 1rem;
            background-color: #e9ecef; /* Simulate disabled background */
            color: #6c757d; /* Simulate disabled text */
            margin-top: 8px; /* Align with label */
            cursor: default; /* Indicate non-interactive */
        }
        button#compressButton {
            background-color: #007bff;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 1rem;
            font-weight: 600;
            transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease;
            display: block;
            width: 100%;
            margin-top: 15px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.075);
        }
        button#compressButton:hover {
            background-color: #0056b3;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        button#compressButton:disabled {
            background-color: #adb5bd;
            cursor: not-allowed;
            box-shadow: none;
        }
        #status {
            margin-top: 35px;
            padding: 12px 15px;
            border-radius: 4px;
            background-color: #e9ecef;
            border: 1px solid #ced4da;
            text-align: center;
            font-weight: 500;
            color: #495057;
            transition: background-color 0.3s ease;
        }
         #status.processing {
             background-color: #fff3cd;
             border-color: #ffeeba;
             color: #856404;
         }
         #status.error {
             background-color: #f8d7da;
             border-color: #f5c6cb;
             color: #721c24;
         }
         #status.success {
             background-color: #d4edda;
             border-color: #c3e6cb;
             color: #155724;
         }
        #results {
            margin-top: 35px;
            border: 1px solid #dee2e6;
            border-radius: 4px;
            overflow: hidden;
        }
         #results h2 {
            background-color: #f8f9fa;
            margin: 0;
            padding: 12px 15px;
            font-size: 1.1rem;
            font-weight: 600;
             border-bottom: 1px solid #dee2e6;
             color: #495057;
        }
        .result-item {
            background-color: #fff;
            border-bottom: 1px solid #e9ecef;
            padding: 12px 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            font-size: 0.95rem;
            transition: background-color 0.1s ease-in-out;
        }
        .result-item:nth-child(odd) {
            background-color: #f8f9fa;
        }
        .result-item:last-child {
            border-bottom: none;
        }
        .result-details {
            display: flex;
            flex-direction: column;
            flex-grow: 1;
            margin-right: 15px;
        }
        .file-name {
            font-weight: 600;
            color: #343a40;
            word-break: break-all;
        }
        .status-text {
             margin-top: 4px;
        }
        .status-success {
            color: #155724;
            font-weight: 500;
        }
        .status-failure {
            color: #721c24;
            font-weight: 500;
        }
        .error-message {
            font-size: 0.9em;
            color: #6c757d;
            margin-top: 3px;
            word-break: break-word;
        }
        .final-size {
            font-size: 0.9em;
            color: #6c757d;
             margin-top: 3px;
        }
        a.download-link {
            margin-left: auto;
            padding: 6px 12px;
            background-color: #28a745;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            font-size: 0.9em;
            white-space: nowrap;
             transition: background-color 0.2s ease;
        }
        a.download-link:hover {
            background-color: #218838;
        }

        .instructions-container {
            background-color: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 6px;
            padding: 20px 25px;
            margin-top: 40px;
            margin-bottom: 35px;
            font-size: 0.95em;
            color: #495057;
        }
        .instructions-container h2 {
            margin-top: 0;
            margin-bottom: 18px;
            font-size: 1.15rem;
            font-weight: 600;
            color: #343a40;
            text-align: center;
            border-bottom: 1px solid #dee2e6;
            padding-bottom: 10px;
        }
        .instructions-container ul {
            list-style: none;
            padding-left: 0;
            margin-bottom: 0;
        }
        .instructions-container > ul > li {
            margin-bottom: 14px;
            padding-left: 22px;
            position: relative;
        }
        .instructions-container > ul > li::before {
            content: "\2022";
            color: #007bff;
            font-weight: bold;
            font-size: 1.2em;
            display: inline-block;
            position: absolute;
            left: 0;
            top: -1px;
        }
        .instructions-container ul ul {
            margin-top: 8px;
            margin-bottom: 8px;
            padding-left: 18px;
        }
         .instructions-container ul ul li {
             margin-bottom: 6px;
             font-size: 0.98em;
             list-style: none;
             position: relative;
             padding-left: 15px;
         }
        .instructions-container ul ul li::before {
             content: "\25E6";
             color: #495057;
             display: inline-block;
             position: absolute;
             left: 0;
             top: 1px;
             font-size: 0.8em;
         }
        .instructions-container li strong {
            color: #212529;
            font-weight: 600;
        }
    </style>
</head>
<body>

<div class="container">
    <h1>图片压缩工具</h1>

    <div class="form-group">
        <label for="fileInput">选择图片文件 (可多选):</label>
        <input type="file" id="fileInput" name="files" multiple accept="image/jpeg, image/png, image/webp, image/gif, image/bmp">
        <div id="selectedFilesInfo" class="selected-files-info" style="display: none;"></div>
    </div>

    <div class="form-group">
        <label for="outputFormat">选择输出格式:</label>
        <p class="output-format-display" id="outputFormatDisplay">JPEG (.jpg)</p>
    </div>

    <button id="compressButton">开始压缩</button>

    <div id="status">准备就绪</div>

    <div id="results" style="display: none;">
        <h2>处理结果:</h2>
        <div id="result-list">
            <!-- Results will be inserted here -->
        </div>
    </div>

    <div class="instructions-container" style="margin-top: 35px;">
        <h2>使用说明与提示</h2>
        <ul>
            <li><strong>批量处理</strong>: 您可以一次选择并上传多个图片文件进行处理。</li>
            <li><strong>支持的输入格式</strong>: 工具可以读取常见的图片格式，如 JPEG, PNG, BMP, GIF 等。（注意：最终输出固定为 JPEG 格式）。</li>
            <li><strong>分辨率自动调整</strong>:
                <ul>
                    <li>如果上传图片的最短边（宽度和高度中的较小值）<strong>大于 1080 像素</strong>，工具会自动将其<strong>等比例缩小</strong>，使最短边等于 1080 像素。</li>
                    <li>如果最短边<strong>小于或等于 1080 像素</strong>，则保持图片的原始分辨率不变。</li>
                </ul>
            </li>
            <li><strong>压缩核心目标</strong>: 最终输出的图片文件大小<strong>严格确保小于或等于 2MB</strong>。</li>
            <li><strong>压缩策略 (JPEG)</strong>:
                <ul>
                    <li>工具会首先尝试在较高图像质量下进行压缩。</li>
                    <li><strong>如果高质量压缩后文件仍然大于 2MB</strong>，工具将<strong>自动逐步降低 JPEG 的质量</strong>，反复尝试，直到文件大小满足小于等于 2MB 的要求，或者达到预设的最低可接受质量下限。</li>
                </ul>
            </li>
            <li><strong>注意</strong>: 压缩效果受原始图片内容影响。对于某些非常复杂或已经高度压缩的图片，即使降低到较低质量，也可能无法成功压缩到 2MB 以下，此时该文件处理状态会显示为失败。</li>
        </ul>
    </div>

</div>

<script src="script.js"></script>
</body>
</html> 